package com.timemanager.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.timemanager.R;
import com.timemanager.model.EventAndEventTime;
import com.timemanager.util.Utility;

import java.util.List;

/**
 * Created by He ZQ on 2016/3/28.
 * Email: Alexmocer@hotmail.com
 */
public class EventAndEventTimeAdapter extends ArrayAdapter<EventAndEventTime> {

    private int resourceId;
    public EventAndEventTimeAdapter(Context context, int textViewResourceId,
                                    List<EventAndEventTime> objects) {
        super(context, textViewResourceId, objects);
        resourceId = textViewResourceId;
    }

    @Override
    public View getView (int position, View convertView, ViewGroup parent) {
        EventAndEventTime eventAndEventTime = getItem(position);
        View view = LayoutInflater.from(getContext()).inflate(resourceId, null);
        TextView eventType = (TextView) view.findViewById(R.id.event_type);
        TextView eventName = (TextView) view.findViewById(R.id.event_name);
        TextView elapsedTime = (TextView) view.findViewById(R.id.elapsed_time);
        TextView startTime = (TextView) view.findViewById(R.id.start_time);
        eventType.setText(eventAndEventTime.getEventType());
        eventName.setText(eventAndEventTime.getEventName());
        elapsedTime.setText(Utility.formatTime(eventAndEventTime.getElapsedTime()));
        startTime.setText(eventAndEventTime.getStartDateTime());
        return view;
    }
}
